<?php

/**
 * Created by PhpStorm.
 * User: Yieong
 * Date: 16/4/5
 * Time: 上午9:43
 */
class ShutupUserController extends AdminBaseController {
    
    public function index(){
    	$this->setTitle('角色禁言列表');
    
    	$filter = new PubFilter();
    	$grid   = new PubGrid();
    
//     	$filter->addSeaOsFilter();
//     	$filter->addOssServer(true)
    	$filter->addSeaSpecialFilter(true);
    	$filter->addSeaOsFilterAll();
    	$filter->addOssServerAll()
    	->addFilter('begin', 'input', '创建时间', array('date' => 'day'))
    	->addFilter('end', 'input', '至', array('date' => 'day'));
    
    	$params = $filter->get();
    	$header = ShutupUserService::indexHeader();
    	$data   = ShutupUserService::indexData($params);
    
    	$grid->addGrid($header, $data);
    
    	$this->out['filter'] = $filter->show();
    	$this->out['grid'] = $grid->show();
    }



    public function add(){
        $this->setTitle('角色禁言');

        //$this->out['serverList']    = ServerService::getOptions();
        $this->out['channelType']   = ShutupUserService::channelType();
        
        $osList = PubAuthSession::get('os');
        $this->out['osList']      = $osList;
        
        $this->out['serverList'] = ServerService::getOptions1();

    }

    public function doAdd(){
    	$result = ShutupUserService::doAdd($_POST);
    
    	if($result['state']){
    		$this->showMessage('发送成功', PubFunc::buildUrl('/oss/?r=shutupUser/index'));
    	}else{
    		$this->showMessage($result['msg']);
    	}
    }
    
    public function delete(){
    	$id = $this->R('id');
    
    	$result = ShutupUserService::delete($id);
    
    	if($result !== false){
    		$this->showMessage('删除成功', PubFunc::buildUrl("/oss/?r=shutupUser/index"));
    	}else{
    		$this->showMessage('删除失败');
    	}
    }
    
    
    public function untie(){
    	$result = array();
    	$id = $this->R('id');

    	$info = ShutupUserService::get($id);
    	$info['status'] = 0;
    	$info['server'] = $info['server_id'];
    	$result = ShutupUserService::send($info);
    	//$result['state'] = true;
    	if($result['state']){
    		$this->out = array(
    				'status' => 1,
    				'msg' => '解封成功',
    				'data'    => ''
    		);
    		//解封成功后，改变status
    		$result = ShutupUserService::doEdit($id, $info);
    	}else{
    		$this->out = array(
    				'status' => 1,
    				'msg' => $result['msg'],
    				'data'    => ''
    		);
    	}  	
    	
    	$this->outType = 'json';
    }

}